/**
 * Created by XianTao on 2016/11/6
 * <p/>
 * Copyright (c) 2015-2015
 * Apache License
 * Version 2.0, January 2004
 * http://www.apache.org/licenses/
 */
package org.lego.wechat.base.service;

import org.lego.jpa.base.repository.BaseRepository;
import org.lego.jpa.base.service.BaseService;
import org.lego.jpa.base.util.DynamicSpecifications;
import org.lego.wechat.base.entity.WxJsTicket;
import org.lego.wechat.base.repository.WxJsTicketRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class WxJsTicketService extends BaseService<WxJsTicket, String> {
    @Autowired
    private WxJsTicketRepository wxJsTicketRepository;

    @Override
    protected BaseRepository<WxJsTicket, String> getRepository() {
        return wxJsTicketRepository;
    }

    public WxJsTicket findOneByCorpIdAndAgentId(String corpId, Integer agentId) {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("EQ_corpId", corpId);
        condition.put("EQ_agentId", agentId);
        Specification<WxJsTicket> specification = DynamicSpecifications.buildSpecification(condition, WxJsTicket.class);
        return findOne(specification);
    }
}
